/*
package com.ywf.corebase.common.utils;

import java.net.Inet4Address;
import java.net.InetAddress;

import java.net.NetworkInterface;

import java.net.SocketException;
import java.util.Enumeration;

import javax.servlet.http.HttpServletRequest;

import org.apache.log4j.Logger;

import net.sf.json.JSONObject;

public class IpUtils {

	private static final  Logger logger = Logger.getLogger(IpUtils.class);

    private static final String[] HEADERS = {
        "X-Forwarded-For",
        "Proxy-Client-IP",
        "WL-Proxy-Client-IP",
        "HTTP_X_FORWARDED_FOR",
        "HTTP_X_FORWARDED",
        "HTTP_X_CLUSTER_CLIENT_IP",
        "HTTP_CLIENT_IP",
        "HTTP_FORWARDED_FOR",
        "HTTP_FORWARDED",
        "HTTP_VIA",
        "REMOTE_ADDR",
        "X-Real-IP"
    };

    */
/**
     * 判断ip是否为空，空返回true
     * @param ip
     * @return
     *//*

    public static boolean isEmptyIp(final String ip){
        return (ip == null || ip.length() == 0 || ip.trim().equals("") || "unknown".equalsIgnoreCase(ip));
    }


    */
/**
     * 判断ip是否不为空，不为空返回true
     * @param ip
     * @return
     *//*

    public static boolean isNotEmptyIp(final String ip){
        return !isEmptyIp(ip);
    }

    */
/***
     * 获取客户端ip地址(可以穿透代理)
     * @param request HttpServletRequest
     * @return
     *//*

    public static String getIpAddress(HttpServletRequest request) {
        String ip = "";
        for (String header : HEADERS) {
            ip = request.getHeader(header);
            if(isNotEmptyIp(ip)) {
                 break;
            }
        }
        if(isEmptyIp(ip)){
            ip = request.getRemoteAddr();
        }
        if(isNotEmptyIp(ip) && ip.contains(",")){
            ip = ip.split(",")[0];
        }
        if("0:0:0:0:0:0:0:1".equals(ip)){
            ip = "127.0.0.1";
        }
        return ip;
    }


    */
/**
     * 获取本机的局域网ip地址，兼容Linux
     * @return String
     * @throws Exception
     *//*

    public static String getLocalHostIP(){
        Enumeration<NetworkInterface> allNetInterfaces = null;
        String localHostAddress = "";
        try {
            allNetInterfaces = NetworkInterface.getNetworkInterfaces();
            while(allNetInterfaces.hasMoreElements()){
                NetworkInterface networkInterface = allNetInterfaces.nextElement();
                Enumeration<InetAddress> address = networkInterface.getInetAddresses();
                while(address.hasMoreElements()){
                    InetAddress inetAddress = address.nextElement();
                    if(inetAddress != null && inetAddress instanceof Inet4Address){
                        localHostAddress = inetAddress.getHostAddress();
                    }
                }
            }
        } catch (SocketException e) {
            logger.error("IpUtils-->getLocalHostIP-->isError");
        }
        return localHostAddress;
    }

    */
/**
     * 高德地图IP地址获取城市信息
     * @param apiUrl
     * @param ipAddress
     * @url https://restapi.amap.com/v3/ip
     * @return
     * @throws Exception
     *//*

    public static SimpleMap getGDIPLocationCityInfo(String apiUrl, String ipAddress)
            throws Exception {
    	SimpleMap dataObject = new SimpleMap();
    	StringBuffer data = new StringBuffer();
		data.append("&key=").append("10c42effa1449756608e52c1ddbc0528");
		data.append("&output=").append("JSON");
		data.append("&ip=").append(ipAddress);
		JSONObject jsonResult = HttpUtils.getInstance().postHttpRequestForJSONObject(apiUrl,data.toString());
		if(jsonResult.getInt("status")==1){
			String provinceID = jsonResult.has("adcode")?jsonResult.getString("adcode"):"";
			String provinceName = jsonResult.has("province")?jsonResult.getString("province"):"";
			String cityName = jsonResult.has("city")?jsonResult.getString("city"):"";
			dataObject.set("provinceID", provinceID);
			dataObject.set("cityInfo", provinceName+":"+cityName);
		}
		return dataObject;
    }

    */
/**
     * 腾讯地图IP地址获取城市信息
     * @param apiUrl
     * @param ipAddress
     * @url https://apis.map.qq.com/ws/location/v1/ip
     * @return
     * @throws Exception
     *//*

    public static SimpleMap getTXIPLocationCityInfo(String apiUrl, String ipAddress)
            throws Exception {
    	SimpleMap dataObject = new SimpleMap();
    	StringBuffer data = new StringBuffer();
    	data.append(apiUrl);
		data.append("?key=").append("SVUBZ-ZHR3O-ADQW7-S4V2Y-UQZH6-NMBLP");
		data.append("&output=").append("JSON");
		data.append("&ip=").append(ipAddress);
		JSONObject jsonResult = HttpUtils.getInstance().doGetForTxHttp(data.toString());
		if(jsonResult.getInt("status")==0){
			JSONObject resultJson = jsonResult.getJSONObject("result");
			if(resultJson!=null){
				JSONObject adInfoJson = resultJson.getJSONObject("ad_info");
				if(adInfoJson!=null){
					String adCode = adInfoJson.has("adcode")?adInfoJson.getString("adcode"):"";
					String provinceID = String.format("%-6s", adCode.substring(0, 2)).replace(" ", "0");
					String cityInfo = new StringBuilder().append(adInfoJson.getString("province")).
							append(adInfoJson.getString("city")).append(adInfoJson.getString("district")).toString();
					dataObject.set("adCode", adCode);
					dataObject.set("provinceID", provinceID);
					dataObject.set("cityInfo", cityInfo);
				}
			}
		}
		return dataObject;
    }
}
*/
